package com.ruoyi.pos.domain.dto.transaction.request;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.List;

/**
 * 销售小票创建请求DTO
 * 
 * @author ruoyi
 * @date 2025-01-30
 */
@Data
@ApiModel(description = "销售小票创建请求")
public class SaleTicketCreateRequest {

    @ApiModelProperty(value = "销售流水号", required = true)
    @NotBlank(message = "销售流水号不能为空")
    private String transactionNo;

    @ApiModelProperty(value = "本地销售号")
    private String localTransactionNo;

    @ApiModelProperty(value = "设备ID", required = true)
    @NotNull(message = "设备ID不能为空")
    private Long deviceId;

    @ApiModelProperty(value = "柜组ID", required = true)
    @NotNull(message = "柜组ID不能为空")
    private Long groupId;

    @ApiModelProperty(value = "收银员ID", required = true)
    @NotNull(message = "收银员ID不能为空")
    private Long cashierId;

    @ApiModelProperty(value = "会员ID")
    private Long memberId;

    @ApiModelProperty(value = "单据类型", required = true, example = "SALE", allowableValues = "SALE,REFUND")
    @NotBlank(message = "单据类型不能为空")
    private String documentType;

    @ApiModelProperty(value = "商品总数量", required = true)
    @NotNull(message = "商品总数量不能为空")
    private Integer totalQuantity;

    @ApiModelProperty(value = "商品总金额", required = true)
    @NotNull(message = "商品总金额不能为空")
    private BigDecimal totalAmount;

    @ApiModelProperty(value = "折扣金额")
    private BigDecimal discountAmount;

    @ApiModelProperty(value = "实付金额", required = true)
    @NotNull(message = "实付金额不能为空")
    private BigDecimal payAmount;

    @ApiModelProperty(value = "找零金额")
    private BigDecimal changeAmount;

    @ApiModelProperty(value = "备注")
    private String remark;

    @ApiModelProperty(value = "销售明细列表", required = true)
    @NotEmpty(message = "销售明细不能为空")
    @Valid
    private List<SaleDetailRequest> saleDetails;

    @ApiModelProperty(value = "支付信息列表", required = true)
    @NotEmpty(message = "支付信息不能为空")
    @Valid
    private List<SalePayRequest> salePays;

    /**
     * 销售明细请求DTO
     */
    @Data
    @ApiModel(description = "销售明细请求")
    public static class SaleDetailRequest {

        @ApiModelProperty(value = "商品ID", required = true)
        @NotNull(message = "商品ID不能为空")
        private Long goodsId;

        @ApiModelProperty(value = "商品编码", required = true)
        @NotBlank(message = "商品编码不能为空")
        private String goodsCode;

        @ApiModelProperty(value = "商品名称", required = true)
        @NotBlank(message = "商品名称不能为空")
        private String goodsName;

        @ApiModelProperty(value = "销售数量", required = true)
        @NotNull(message = "销售数量不能为空")
        private Integer quantity;

        @ApiModelProperty(value = "销售单价", required = true)
        @NotNull(message = "销售单价不能为空")
        private BigDecimal unitPrice;

        @ApiModelProperty(value = "销售金额", required = true)
        @NotNull(message = "销售金额不能为空")
        private BigDecimal amount;

        @ApiModelProperty(value = "折扣率")
        private BigDecimal discountRate;

        @ApiModelProperty(value = "折扣金额")
        private BigDecimal discountAmount;

        @ApiModelProperty(value = "是否赠品", example = "N")
        private String isGift = "N";
    }

    /**
     * 销售支付请求DTO
     */
    @Data
    @ApiModel(description = "销售支付请求")
    public static class SalePayRequest {

        @ApiModelProperty(value = "支付方式ID", required = true)
        @NotNull(message = "支付方式ID不能为空")
        private Long paymentTypeId;

        @ApiModelProperty(value = "支付方式编码", required = true)
        @NotBlank(message = "支付方式编码不能为空")
        private String paymentTypeCode;

        @ApiModelProperty(value = "支付金额", required = true)
        @NotNull(message = "支付金额不能为空")
        private BigDecimal paymentAmount;

        @ApiModelProperty(value = "支付流水号")
        private String paymentNo;

        @ApiModelProperty(value = "支付状态", example = "SUCCESS", allowableValues = "SUCCESS,FAILED,PENDING")
        private String paymentStatus = "SUCCESS";

        @ApiModelProperty(value = "支付备注")
        private String paymentRemark;
    }
}